﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using Microsoft.Xna.Framework.Graphics;

using TomShane.Neoforce.Controls;
using tactics.Interfaces;

namespace tactics.GUI
{
    using FormatMap = Dictionary<string, string>;
    using ScreenCoords = Utility.Pair<int, int>;

    public class TurnCard : IGUIParsable
    {
        Manager guiManager;

        FormatMap formats;

        ScreenCoords position;

        Panel backPanel;
        TextBox status;

        #region properties

        public String Text
        {
            set
            {
                status.Text = string.Format(formats["StatusText"], value);
            }
        }

        public Color Colour
        {
            set
            {
                status.Color = value;
            }
        }

        #endregion

        public TurnCard(Manager guiManagerIn, string xmlFile)
        {
            InitControls(guiManagerIn);
            GUIBuilder.BuildGUI(this, guiManager, xmlFile, "TurnCard");
            SetInfoDisplay();
        }

        public void Remove()
        {
            guiManager.Remove(backPanel);
        }

        private void InitControls(Manager guiManagerIn)
        {
            guiManager = guiManagerIn;
           
            formats = new FormatMap();

            position = new ScreenCoords();

            backPanel = new Panel(guiManager);
            backPanel.Init();

            status = new TextBox(guiManager);
            status.Init();
        }

        private void SetInfoDisplay()
        {
            UpdatePosition();
        }

        public void UpdatePosition()
        {
            backPanel.Left = (TacticsEngine.Instance.GraphicsManager.PreferredBackBufferWidth / 2) - (backPanel.Width / 2);
        }

        public Control Parse(XmlReader r, string controlName)
        {
            Control found = null;

            if (controlName == "BackPanel")
            {
                GUIBuilder.ParseControl<Panel>(r, backPanel);
                found = backPanel;
            }
            else if (controlName == "StatusText")
            {
                GUIBuilder.ParseControl<TextBox>(r, status);
                formats[controlName] = status.Text;
                found = status;
            }

            return found;
        }
    }
}
